\chapter{The throw state}
\label{chap:throw}
The throw state that is called by the main state machine throws the ball on the beam to one of three positions depending on the given ball size, that was detected by the "BeamAndBallRegul" (see \ref{sec:ball}).

\section{Working principle}
It is implemented using a simple state machine. It uses the beam- and the ball and beam controller to fulfill its task. The throwing works in four steps (can be seen in figure \ref{fig:statemachine}) that are parametrized by five variables. That makes it easier to program and to tune.
\begin{itemize}
\item Set the reference for the ball controller to \textit{position 1} and wait until the ball has reached it 
\item Set a reference for the beam controller and wait \textit{time 1} milliseconds
\item Set a reference for the beam controller and wait \textit{time 2} milliseconds
\end{itemize}
After this the \textit{"done"}-flag is set to signal the state machine that it can continue.

\section{Implementation}
The throw class runs as an own thread. It communicates via methods that could set the ball size and stop/restart the state machine and a method that returns the value of the \textit{"done"}-flag.

The state machine in the throw class only executes some actions in the first execution of a state (e.g. sets a new reference ad starts the controller) and then waits for the condition to become true.

As the task is not very time critical, but still needs a certain speed to get accurate waiting times which is important for the throwing, the cycle time is set to two milliseconds.
